# blotter testframe

if('package:blotter' %in% search() || require('blotter',quietly=TRUE)) {}

ls(envir=.blotter)    # list objects in blotter environment
ls_instruments()      # list financial instruments

currency("USD")
symbols=c("IBM", "CSCO")

for (symbol in symbols) {
  stock(symbol, currency="USD", multiplier=1)
}

# receive price data
getSymbols(symbols, src="yahoo")

# initalize a portfolio object 'p'. this happens in envir=.blotter
initPortf("p", symbols=symbols, currency="USD")

# adding trades to portfolio 'p'
addTxn("p", Symbol="IBM", TxnDate ='2007-01-03', TxnQty=50, TxnPrice= 96.50, TxnFees= -0.05*50)
addTxn("p", "CSCO", "2007-01-05", 100, TxnPrice=28.5, TxnFees=-10)

# now update portfolio
updatePortf("p", Dates="2007-01")

# now create account 'a' for portfolio 'p'
initAcct(name="a", portfolio="p", initEq=10000, currency="USD")

# now update the account
updateAcct("a", "2007-01")
updateEndEq("a", "2007-01")

PortfReturns(Account="a", Dates="2007", Portfolios="p")

# examine the contents of the portfolio
# -- this is the transaction record
getTxns("p", Symbol="IBM", Date="2007-01")

# -- these are the resulting positions (date has to be a day)
getPos("p", Symbol="IBM", Date="2007-01-03")
getPosQty("p", Symbol="IBM", Date="2007-01-03")

# now draw a chart
chart.Posn(Portfolio="p", Symbol="IBM", Dates="2007-01")
chart.Posn(Portfolio="p", Dates="2007-01")


